import 'package:banyou_app/app/config/colors.dart';
import 'package:banyou_app/app/routes/app_pages.dart';
import 'package:banyou_app/app/widget/login_button.dart';
import 'package:banyou_app/app/widget/login_input.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/login_controller.dart';

class LoginView extends GetView<LoginController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Obx(() => controller.showview.value == false
          ? Container()
          : Stack(
              children: [
                Positioned.fill(
                    child: Image.asset(
                  'assets/images/背景@2x.png',
                  width: 1.sw,
                  height: 1.sh,
                  fit: BoxFit.cover,
                )),
                Positioned.fill(
                  child: SingleChildScrollView(
                    child: Container(
                      height: 1.sh,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          SizedBox(height: 100),
                          Container(
                            padding: EdgeInsets.only(left: 31),
                            alignment: Alignment.centerLeft,
                            child: Text('验证码登录',
                                style: TextStyle(
                                  fontSize: 28.sp,
                                  fontWeight: FontWeight.w700,
                                  color: ColorConfig.text_label,
                                )),
                          ),
                          SizedBox(
                            height: 20,
                          ),
                          Container(
                              decoration: BoxDecoration(
                                  color: ColorConfig.white,
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(30)),
                                  border: Border.all(color: Color(0x1A131313))),
                              margin: EdgeInsets.symmetric(horizontal: 31),
                              alignment: Alignment.center,
                              padding: EdgeInsets.symmetric(
                                horizontal: 15,
                              ),
                              child: LoginInput(
                                title: "",
                                hint: "请输入手机号",
                                keyBoardType: TextInputType.phone,
                                inputFormatters: [
                                  FilteringTextInputFormatter.digitsOnly,
                                  LengthLimitingTextInputFormatter(11)
                                ],
                                onChanged: (text) {
                                  controller.phone = text;
                                  // controller.checkInput();
                                },
                              )),
                          SizedBox(
                            height: 20,
                          ),
                          Container(
                            decoration: BoxDecoration(
                                color: ColorConfig.white,
                                borderRadius:
                                    BorderRadius.all(Radius.circular(30)),
                                border: Border.all(color: Color(0x1A131313))),
                            margin: EdgeInsets.symmetric(horizontal: 31),
                            padding: EdgeInsets.symmetric(
                              horizontal: 15,
                            ),
                            child: LoginInput(
                              title: "",
                              hint: "请输入验证码",
                              inputFormatters: [
                                FilteringTextInputFormatter.digitsOnly,
                                LengthLimitingTextInputFormatter(6)
                              ],
                              rightWidget: TextButton(
                                onPressed: () {
                                  controller.getCode();
                                },
                                child: Obx(() => Text(controller.codeStr.value,
                                    style: TextStyle(
                                      fontSize: 14.sp,
                                      color: ColorConfig.app_main,
                                    ))),
                              ),
                              keyBoardType: TextInputType.number,
                              onChanged: (text) {
                                controller.code = text;
                              },
                            ),
                          ),
                          SizedBox(height: 5),

                          SizedBox(
                            height: 40.h,
                          ),
                          InkWell(
                            child: Container(
                              width: 1.sw,
                              margin: EdgeInsets.symmetric(horizontal: 31),
                              height: 50,
                              decoration: BoxDecoration(
                                gradient: LinearGradient(
                                    begin: Alignment.centerLeft,
                                    end: Alignment.centerRight,
                                    colors: [
                                      Color(0xFFF52EC5),
                                      Color(0xFFFF8A33),
                                    ]),
                                borderRadius: BorderRadius.circular(50),
                              ),
                              child: Center(
                                child: Text(
                                  "登录",
                                  style: TextStyle(
                                      color: ColorConfig.white,
                                      fontSize: 16,
                                      fontWeight: FontWeight.w500),
                                ),
                              ),
                            ),
                            onTap: controller.send,
                          ),
                          // Container(
                          //   width: 1.sw,
                          //   height: 50,
                          //   margin: EdgeInsets.symmetric(horizontal: 31),

                          //   child: LoginButton(
                          //     "登录",
                          //     enable: true,
                          //     onPressed: controller.send,
                          //   ),
                          // ),
                          Spacer(),
                          Container(
                            width: 1.sw,
                            margin: EdgeInsets.symmetric(horizontal: 31),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Obx(() => InkWell(
                                    child: Icon(
                                      controller.protect.value
                                          ? Icons.check_box
                                          : Icons.check_box_outline_blank,
                                      size: 20.r,
                                      color: ColorConfig.app_main,
                                    ),
                                    onTap: controller.changeAgree)),
                                const SizedBox(
                                  width: 2,
                                ),
                                Text.rich(TextSpan(children: [
                                  TextSpan(
                                    text: '同意',
                                    style: TextStyle(
                                        fontSize: 13.0.sp,
                                        color: Color(0xFF9D9D9D)),
                                    recognizer: TapGestureRecognizer()
                                      ..onTap = () {
                                        controller.changeAgree();
                                      },
                                  ),
                                  TextSpan(
                                      text: '《用户协议》',
                                      recognizer: TapGestureRecognizer()
                                        ..onTap = () {
                                          Get.toNamed(Routes.WEB, arguments: {
                                            "title": '用户协议',
                                            "url":
                                                'https://aqcdn.olbibo.com.cn/Static/UserAgreement.html',
                                          });
                                        },
                                      style: TextStyle(
                                          fontSize: 13.sp,
                                          color: ColorConfig.app_main)),
                                  TextSpan(
                                      text: '和',
                                      style: TextStyle(
                                          fontSize: 13.0.sp,
                                          color: Color(0xFF9D9D9D))),
                                  TextSpan(
                                      text: '《隐私政策》',
                                      recognizer: TapGestureRecognizer()
                                        ..onTap = () {
                                          Get.toNamed(Routes.WEB, arguments: {
                                            "title": '隐私政策',
                                            "url":
                                                'https://aqcdn.olbibo.com.cn/Static/PrivacyPolicy.html',
                                          });
                                        },
                                      style: TextStyle(
                                          fontSize: 13.sp,
                                          color: ColorConfig.app_main)),
                                ]))
                              ],
                            ),
                          ),
                          SizedBox(
                            height: 40.h,
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            )),
    );
  }
}
